package com.sicaolong.eventdefine.util;

import org.springframework.context.ApplicationContext;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class SpringContextUtil {
    private static ApplicationContext ac;

    public static <T> T getBean(String beanName, Class<T> clazz) {
        T bean = ac.getBean(beanName, clazz);
        return bean;
    }

    public static <T> List<T> getBeans(Class<T> clazz) {
        Map<String, T> beansOfType = ac.getBeansOfType(clazz);
        return new ArrayList<>(beansOfType.values());
    }

    public static void setApplicationContext(ApplicationContext applicationContext) {
        ac = applicationContext;
    }
}
